package org.dawfinn.droiditarian.server.data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class DeedLocation {

	public static final long MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;

	@Persistent
	private String deedTitle;

	@Persistent
	private Date completedDate;

	@Persistent
	private Blob image;

	@Persistent
	private String geohash;

	@Persistent
	private String locality;
	
	@Persistent
	private String adminArea;

	@Persistent
	private String country;

	@Persistent
	private Integer timesQueried;

	@Persistent
	private ArrayList<ReportReason> reports;
//
//	@Persistent
//	private Long days;

	@PersistenceCapable
	@EmbeddedOnly
	public static enum ReportReason {
		SEXUAL, VIOLENT, OFFENSIVE, INAPPROPRIATE;
	}

	public DeedLocation(String deedTitle, Date completedDate, Blob image, String geohash, String locality, String adminArea, String country) {
		this.geohash = geohash;
		this.deedTitle = deedTitle;
		this.completedDate = completedDate;
		this.image = image;
		this.locality = locality;
		this.adminArea = adminArea;
		this.country = country;
		this.timesQueried = 0;
		this.reports = new ArrayList<ReportReason>();
//		calculateDays();
	}

	public Key getKey() {
		return key;
	}

	public String getDeedTitle() {
		return deedTitle;
	}

	public Blob getImage() {
		return image;
	}

	public void setDeedTitle(String deedTitle) {
		this.deedTitle = deedTitle;
	}

	public void setImage(Blob image) {
		this.image = image;
	}

	public void setCompletedDate(Date completedDate) {
		this.completedDate = completedDate;
	}

	public Date getCompletedDate() {
		return completedDate;
	}

	public String getGeohash() {
		return geohash;
	}

	public void setGeohash(String geohash) {
		this.geohash = geohash;
	}

	public String getLocality() {
		return locality;
	}

	public void setLocality(String locality) {
		this.locality = locality;
	}

	public void setAdminArea(String adminArea) {
		this.adminArea = adminArea;
	}

	public String getAdminArea() {
		return adminArea;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public Integer getTimesQueried() {
		return timesQueried;
	}

	public void setTimesQueried(Integer timesQueried) {
		this.timesQueried = timesQueried;
	}

	public List<ReportReason> getReports() {
		return reports;
	}

	public void setReports(ArrayList<ReportReason> reports) {
		this.reports = reports;
	}

	public void addReport(ReportReason report) {
		if (this.reports == null) {
			this.reports = new ArrayList<ReportReason>();
		}
		this.reports.add(report);
	}

	public String getWebsafeKey() {
		return KeyFactory.keyToString(key);
	}

//	public Long getDays() {
//		return days;
//	}
//
//	public void calculateDays() {
//		this.days = completedDate.getTime() / MILLISECONDS_PER_DAY;
//	}
}
